//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2004-2007
//
// Object properties dialog - 'Source' page.
//

# include "StdAfx.h"
# include "Resource.h"
# include "RgnProperties.h"
# include "Map.h"
# include "ShowFile.h"
# include "Settings.h"

bool CRgnSourcePage::OnInit (HWND _hwndFocus) {
	const size_t cObjectSize = m_rgn.cEndPos - m_rgn.cBeginPos;

	SetDlgItemText (IDC_ORDINAL, "-"); // m_rgn.cOrdinal
	SetDlgItemTextF (IDC_LINE,   "%d",  m_rgn.cFileLine);
	SetDlgItemTextF (IDC_OFFSET, "%Xh", m_rgn.cBeginPos);
	SetDlgItemTextF (IDC_OSIZE,  "%d",  cObjectSize);
	
	//
	// Prepare source edit box.
	//

	if (m_rgn.pFileRef) {
		SetDlgItemText (IDC_FILE_NAME, m_rgn.pFileRef->strFileName.c_str ());
		ShowFileOffsetCtl (m_hWnd, IDC_SOURCE, m_rgn.pFileRef->strFileName.c_str (), m_rgn.cBeginPos, cObjectSize);
		if (m_rgn.dwFlags & rgn_t::fModified)
			EnableDlgItem (IDC_SOURCE, false);
		else {
			::SetFocus (::GetDlgItem (m_hWnd, IDC_SOURCE));
			return FALSE;
		}
	} else {
		SetDlgItemText (IDC_FILE_NAME, "(No associated file)");
		SetDlgItemText (IDC_SOURCE,    "(No associated file)");
	}

	return true;
}
